﻿using System.IO;
using System.ServiceModel;


namespace Objectware.Silverlight.Testing.Runner
{
	public class ServiceLocator
	{
		public static readonly ServiceLocator Default = new ServiceLocator();

		private ServiceLocator()
		{
			
		}

		private void Log(string format, params string[] parameters)
		{
			//File.AppendAllText("c:\\servicelocator.log", string.Format("{0}\n\r", string.Format(format, parameters)));
		}


		public T GetInstance<T>()
			where T:class
		{
			Log("GetInstance<{0}>()",typeof(T).ToString());

			if( typeof(T).Equals(typeof(TestResultService.TestResultService)) )
			{
				var binding = new BasicHttpBinding();
				var url = ServerManager.Instance.TestResultServiceUrl;
				
				Log("ServiceURL : {0}",url);

				var address = new EndpointAddress(url);
				return new TestResultService.TestResultServiceClient(binding,address) as T;
			}
			return null;
		}
	}
}
